package interfacekeyword;

public class ComparableRectangle extends Rectangle implements CompareObject {

    public ComparableRectangle(double width, double height) {
        super(width, height);
    }

    /**
     * 比较两个对象的大小
     *
     * @param o 要比较的对象
     * @return 0 相等；1 当前对象大；-1 当前对象小
     */
    @Override
    public int compareTo(Object o) {
        Rectangle rectangle = (Rectangle) o;

        if (getArea() == rectangle.getArea()){
            return  0;
        }
        else {
            if (getArea() > rectangle.getArea()){
                return 1;
            }
            else {
                return 0;
            }
        }
    }

}
